package com.open.basic.function;

import com.open.basic.Page;
import com.open.basic.exception.BizException;
import org.apache.commons.lang3.StringUtils;

import java.util.function.Consumer;


/**
 * @author: system
 * @Date: 2025/2/24 上午11:22
 * @Version: V1.0
 * @description: |
 */

public class ConsumerUtil {

    /**
     * 字符串空校验
     */
    public static Consumer<String> BLANK_CHECK = (s) -> {
        if (StringUtils.isBlank(s)) {
            throw new BizException("参数不能为空");
        }
    };


    /**
     * Page对象校验
     */
    public static Consumer<Page> PAGE_CHECK = param -> {
        Integer pageNo = param.getPageNo();
        Integer pageSize = param.getPageSize();
        if (pageNo == null) {
            throw new BizException("pageNum不能为空");
        }
        if (pageNo <= 0) {
            throw new BizException("pageNum必须大于等于1");
        }
        if (pageNo >= 2147483647L) {
            throw new BizException("pageNum超过最大值");
        }
        if (pageSize == null) {
            throw new BizException("pageSize不能为空");
        }
        if (pageSize <= 0) {
            throw new BizException("pageSize必须大于等于1");
        }
        if (pageSize > 1000L) {
            throw new BizException("pageSize过大");
        }
    };

}
